The conventional key-operated mechanical lock has been in existence for years, but suffers a number of important drawbacks, including its ability of being opened by master keys which are often easily available to unauthorized persons. Furthermore, burglars are becoming more and more sophisticated in their techniques of securing entries through doors equipped with mechanical locks. In order to overcome the above drawbacks, several types of electro-mechanical locks have been developed. However, these locks, too, have not completely solved the security problem. Electronically-operated locks using optical scanning devices for reading code patterns on a card or on a ring worn by a person, have also been developed. However, the known optical scanners require that the key unit be positioned in a specific orientation with respect to the scanner and/or moved in a specific direction, in order to properly detect the code patterns.